<template>
  <div>
    <el-row>
      <el-button type="primary" @click="deviceDialogVisible=true"><i class="el-icon-circle-plus el-icon--left" />创建</el-button>
      <el-button type="primary" @click="remove"><i class="el-icon-circle-plus el-icon--left" />批量创建以某个点位为基准点的测量组列表</el-button>
    </el-row>
    <el-row>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="selection" width="55" sortable />
        <el-table-column prop="fullName" label="设备全称" sortable />
        <el-table-column prop="name" label="设备简称" sortable />
        <el-table-column prop="type" label="设备类型" sortable />
        <el-table-column prop="address" label="地址" sortable>
          <template slot-scope="scope">
            <i class="el-icon-time" />
            <span>{{ scope.row.address }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="battery" label="电量 %" sortable />
        <el-table-column prop="gmtModified" label="最后一次通讯时间" sortable />
        <el-table-column prop="gmtCreate" label="绑定时间" sortable />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="remove">解除绑定</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <!-- bind new device dialog -->
    <el-dialog :visible.sync="deviceDialogVisible" title="绑定新设备" width="80%">
      <unbound-device />
      <span slot="footer" class="dialog-footer">
        <el-button @click="deviceDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="deviceDialogVisible = false">绑 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import UnboundDevice from './unboundDevice'
export default {
  components: {
    UnboundDevice
  },
  data() {
    return {
      deviceDialogVisible: false,
      tableData: [
        {
          id: 1,
          fullName: '大唐国际水电开发 1 号 点位',
          name: 'zjh-1',
          type: '点位',
          battery: '100',
          gmtCreate: '2018年09月28日13:34:28',
          gmtModified: '2018年09月28日13:34:28',
          address: '上海市普陀区金沙江路 1518 弄'
        },
        {
          id: 2,
          fullName: '大唐国际水电开发 2 号 点位',
          name: 'zjh-2',
          type: '点位',
          battery: '100',
          gmtCreate: '2018年09月28日13:34:28',
          gmtModified: '2018年09月28日13:34:28',
          address: '上海市普陀区金沙江路 1518 弄'
        },
        {
          id: 3,
          fullName: '大唐国际水电开发中控',
          name: 'zjh-3',
          type: '中控',
          battery: '100',
          gmtCreate: '2018年09月28日13:34:28',
          gmtModified: '2018年09月28日13:34:28',
          address: '上海市普陀区金沙江路 1518 弄'
        }
      ]
    }
  },
  methods: {
    remove() {
      this.$confirm('此操作将解除该设备, 是否继续?', '解除绑定', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>
